Allow HomeKit name to be customized#14159
Conversation
|
@cdce8p This is my first draft, take a look and let me know your feedback. As discussed in #14114, this doesn't provide much direct functionality but just gives a cleaner experience for those that care. It's a similar concept to that of the Alexa cloud component. |
|
I have to think about it, but at the moment I'm not convinced this should be added. |
|
There have been a few changes with #14278 |
2509155 to
255a85a
Compare
|
@cdce8p Rebased with the latest updates |
cdce8p
left a comment
There was a problem hiding this comment.
Although I personally don't see much value in it, we can move forward with it.
Can you add tests and update the doc?
There was a problem hiding this comment.
The empty lines between these four config opions (name - serial_number) can be removed
|
Regarding the config dictionary: I was thinking about how we can improve it since I don't Why don't we use the same custruct as for |
|
@cdce8p I updated per your comments, updated the doc, and updated |
|
@schmittx As a starting point take a look at the failing tests: https://travis-ci.org/home-assistant/home-assistant/jobs/375445342#L808. Since acc = GarageDoorOpener(self.hass, 'Cover', garage_door, 2, config=None)
# Would need to change to this:
acc = GarageDoorOpener(self.hass, 'Cover', garage_door, 2)Basically config can be removed, except for Another thing would be to add checks for the newly added vars to And for the |
|
@cdce8p Thanks for the help, I updated/added most of the tests without problem. But, I keep getting a |
cdce8p
left a comment
There was a problem hiding this comment.
I added a few comments that should resolve the failing tests.
Although my initial doubts, this is coming together quite nicely.
Just a few notes FYI:
- Most likely a PR will be merged soon that changes one of the
homekittests, which will require a small rebase #14314 - Even after all changes I would like to wait a few more days (the next weekend, maybe earlier) before I merge this. That way I'm still able to push bug fixes if I need to.
There was a problem hiding this comment.
Can you change the name to test_customize_name? That should be enough.
Also for the first test test_invalid_aid might be better as well. Just noticed it.
There was a problem hiding this comment.
I agree, I cleaned up both names.
There was a problem hiding this comment.
Regarding the actual test:
The type modules are imported dynamically, but not for this test module. Therefore the Light type has to be mocked. The following should work:
def test_customize_name():
"""Test with customized name."""
mock_type = Mock()
with patch.dict(TYPES, {'Light': mock_type}):
config = {CONF_NAME: 'Customize Name'}
acc = get_accessory(None, State('light.demo', 'on'), 2, config)
mock_type.assert_called_with(
None, 'Customize Name', 'light.demo', 2, config)Instead of validation the the display_name is set correctly, we just check that the right name was passed.
There was a problem hiding this comment.
For the alarm_control_panel test:
If you replace this lines: https://github.com/schmittx/home-assistant/blob/b41effa8fad337c7868e1e831835e34420a18916/tests/components/homekit/test_get_accessories.py#L173-L175 with:
self.assertEqual(self.mock_type.call_args[0][-1][ATTR_CODE], '1234')that should solve it.
The reason for this failure was the change from a keyword to a normal argument.
There was a problem hiding this comment.
Awesome, thanks for the assist!
There was a problem hiding this comment.
What do you think of:
for key in (CONF_NAME, CONF_MANUFACTURER,
CONF_MODEL, CONF_SERIAL_NUMBER):
value = config.get(key)
if value:
params[key] = valueThat way we only add dict entries if a value exists. It also fixes test_validate_entity_config.
There was a problem hiding this comment.
Agreed, much cleaner.
There was a problem hiding this comment.
Instead of initializing a new HomeAccessory, just combine it with the previous one.
|
@cdce8p Sounds good to me, this should be good to go now once the tests pass. FYI, I'm also working on adding support for Fan entities. I should have that PR ready later this week or next weekend. |
There was a problem hiding this comment.
I would prefer to use key instead.. index is usually used for an int counter through lists, so it might lead to confusion here.
There was a problem hiding this comment.
key is already used in the top level at line 20, so I went with char in reference to the fact that they're used for characteristic customize.
There was a problem hiding this comment.
Missed that. What do you think of changing the top level one to entity_id and using key here? (At least if I haven't missed something again.)
There was a problem hiding this comment.
I just realized that we wouldn't/can't cover this case otherwise with the accessory below.
We might have to add it back. Sorry for the confusion.
There was a problem hiding this comment.
Added back and cleaned up test_home_accessory, hopefully you agree with my changes.
|
@cdce8p I read through #14330 as well as the repos that it mentioned. I understand the benefit of being able to see the history for accessories and persistent storage but I'd be hesitant to implement it due to the convoluted method required and the need to use the Eve app exclusively (if history is desired). I also think there's a high risk of regular maintenance being needed in the event that Elgato changes their services/characteristics. I think we should focus on using the native Apple HomeKit services/characteristics in order to guarantee a consistent experience for all users, regardless of what app is used (Home, Eve, etc.). For now, I'd vote to focus on improving the current HomeKit component (i.e. add support for more entities like If we run out of things to improve for this component and want to revisit Fakegato in the future then let's worry about the accessory information at that time (Maybe we'd make Fakegato a config option, which would then overwrite any accessory information with unique serial numbers, etc.?) |
|
I agree with almost all of your points. The native services and chars are just easier to maintain at the moment and the focus should be an improving support for other components (eg. Media Player, Fan, ...). What I'm worried about however is that it's quite difficult to take a feature away once it's implemented. If we really decide to implement Therefore I would prefer if we limit the configurable parameters to the |
|
I agree that it's difficult to remove a feature once it's implemented, I just struggle with limiting functionality now in the hopes that we might add something else in future. I'll defer to you in the end though. If we limit the confutable parameters to just name, then I'd propose to close this PR and create a new one. Then we can always come back to this in the future if necessary. |
Take in mind that this doesn't add any new functionality, just the option to customize some additional parts.
We shouldn't do that. This PR has some great foundations in place to implement this feature. A new PR would just copy most of it. A better way might be to create a new PR once this is merge that adds the additional parameters as well and close that for the time being. |
There was a problem hiding this comment.
Can you change key to entity_id in line 19 and 20, the for loop? That way we won't have this problem in the future.
ba7c62d to
040d56b
Compare
|
@schmittx Will take a closer look tomorrow. Thanks for taking the time! |
|
@schmittx BTW: I have started looking into the complete async conversion for the Are you in the HA discord channel? Discussing it there or in direct msg might be the easiest. |
Description:
HomeKit accessory information can be customized by specifying
namewithinentity_config.Related issue (if applicable): N/A
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5314
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: